package com.gl.saasservice.advertisement.controller;

import com.gl.framework.web.response.Result;
import com.gl.saasservice.advertisement.service.SaasAdService;
import com.gl.saasservice.advertisement.vo.AuditVO;
import com.gl.saasservice.advertisement.vo.DeleteVO;
import com.gl.saasservice.advertisement.vo.SaasAdVO;
import com.gl.saasservice.advertisement.vo.StatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 广告位置管理
 */

@Configuration
@Controller
@RequestMapping("/advertisement")
public class SaasAdController {

    @Autowired
    private SaasAdService saasAdService;

    /**
     * 分页列表
     *
     * @param pageNumber
     * @param pageSize
     * @param filter
     * @param sorts
     * @return
     */
    @GetMapping(value = "/pages")
    @ResponseBody
    public Result page(
            @RequestParam(name = "pageNumber", required = true, defaultValue = "0") Integer pageNumber,
            @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize,
            SaasAdVO filter,
            @RequestParam(name = "sort", required = false) String sorts) {
        return saasAdService.pages(pageNumber, pageSize, filter, sorts);
    }


    /**
     * 新增
     */
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Result add( SaasAdVO vo, @RequestParam(value = "file", required = false) MultipartFile file) {
        return saasAdService.add(vo,file);
    }

    /**
     * 编辑
     */
    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public Result update( SaasAdVO vo, @RequestParam(value = "file", required = false) MultipartFile file) {
        return saasAdService.edit(vo,file);
    }

    /**
     * 获取详情
     */
    @GetMapping(value = "/findAdvertisementById")
    @ResponseBody
    public Result findAdvertisementById(@RequestParam Long id) {
        return saasAdService.find(id);
    }

    /**
     * 审核
     * @param vo
     */
    @PutMapping(value = "/audit")
    @ResponseBody
    public Result audit(@RequestBody AuditVO vo) {

        return saasAdService.audit(vo);
    }

    /**
     * 广告上架下架
     * @param vo
     */
    @PutMapping(value = "/status")
    @ResponseBody
    public  Result  advertisingStatus(@RequestBody StatusVO vo) {

        return saasAdService.advertisingStatus(vo);
    }

    /**
     * 选中删除
     * @param vo
     */
    @PutMapping(value = "/selectdelete")
    @ResponseBody
    public  Result  selectDelete(@RequestBody DeleteVO vo ) {

        return saasAdService.selectDelete(vo);
    }


    /**
     * 删除
     */
    @DeleteMapping()
    @ResponseBody
    public Result delete(@RequestParam Long id) {
        return saasAdService.delete(id);
    }

}
